#include <bits/stdc++.h>

using namespace std;

void decimalToOctal(int n, int x) {
    if (n > 0) {
        decimalToOctal(n / x); 
        cout << n % x; 
    }
}

int main() {
    int decimalNumber,x;
    cin >> decimalNumber>>x;
    
    if (decimalNumber == 0) {
        cout << 0; 
    } else {
        decimalToOctal(decimalNumber,x);
    }
    
    return 0;
}
